package fr.afcepf.vod.managedbean;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.primefaces.event.SelectEvent;
import org.primefaces.model.tagcloud.DefaultTagCloudItem;
import org.primefaces.model.tagcloud.DefaultTagCloudModel;
import org.primefaces.model.tagcloud.TagCloudItem;
import org.primefaces.model.tagcloud.TagCloudModel;

import fr.afcepf.vod.entities.Tag;
import fr.afcepf.vod.entities.Video;
import fr.afcepf.vod.metier.IGestionTag;

@ManagedBean
@SessionScoped
public class MbNuageTags {
	
	private List<Video> lesVideos;

	@ManagedProperty(value="#{gestionTagImpl}")
	private IGestionTag gestionTag;
	private TagCloudModel model;
	
	@PostConstruct
	public void initialiserNuage(){
		model = new DefaultTagCloudModel();
		List<Tag> lesTags = gestionTag.getListeTags();
		String label = "";
		Integer strength = 0;
		for(Tag t : lesTags){
			label = gestionTag.getLabel(t);
			strength = gestionTag.getStrength(t);
			model.addTag(new DefaultTagCloudItem(label, strength));
		}
	}
	//Methode pour recuperer le tag choisi !!!!A MODIFIER!!!! 
	public void onSelect(SelectEvent event) {
        TagCloudItem item = (TagCloudItem) event.getObject(); 
        String message = item.getLabel();
        lesVideos = gestionTag.getVideosByTagMessage(message);
        initialiserNuage();
    }
	
	public TagCloudModel getModel() {
		return model;
	}

	public void setModel(TagCloudModel model) {
		this.model = model;
	}

	public IGestionTag getGestionTag() {
		return gestionTag;
	}

	public void setGestionTag(IGestionTag gestionTag) {
		this.gestionTag = gestionTag;
	}
	public List<Video> getLesVideos() {
		return lesVideos;
	}
	public void setLesVideos(List<Video> lesVideos) {
		this.lesVideos = lesVideos;
	}
	
	
	
}
